package com.hph.user.web.controller;

import com.hph.user.domain.User;
import com.hph.user.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Collection;

/**
 * @author {USER}
 * @date {date}
 */
@RestController
public class UserServiceProviderRestApiController {

    @Autowired
    private UserService userServe;

    /**
     * 保存
     * @param name 用户名
     * @return User
     */
    @PostMapping(value = "/user/save")
    public User save(@RequestParam String name){

        User user = new User();

        user.setName(name);

        if(userServe.save(user)){

            return user;
        }else{

            return null;
        }
    }

    @GetMapping(value = "/user/listAll")
    public Collection<User> listAll(){

        return userServe.listAll();
    }
}
